package Server.ServerCore.Service.usyns;

import Server.ExtComponents.BaseConfig.MServerConfig;
import Server.ServerCore.Model.AI.BankerAI;

import Server.ServerCore.Model.Player.PlayerInstance;
import javolution.util.FastList;
import org.springframework.stereotype.Service;

/**
 * @author :石头哥哥<br/>
 *         Project:21Server
 *         Date: 13-4-2
 *         Time: 下午9:19
 */
@Service
public class SingelTableManager{

    public static FastList<SingelTable> tableFastList;//从右往左，0，1，2，3，4

    public void InitSingelTables(){
        tableFastList=new FastList<SingelTable>(MServerConfig.TableNum);
        for (int ID=0;ID!=MServerConfig.TableNum;++ID){
            SingelTable table=new SingelTable(ID);
            tableFastList.add(table);
            BankerAI banker=new BankerAI();
            banker.setID(ID);//bankerAI 编号
            banker.setCircleUnitID(5);//this Fixed is banker seat!
            banker.setTableID(ID);
            table.setBanker(banker);
            table.getGameCharacterFastList().add(banker);
        }
    }


    /**
     * 通过 player 获取 BankerAI
     * @param playerInstance
     * @return
     */
    public BankerAI getBankerAI(PlayerInstance playerInstance){
        return tableFastList.get(playerInstance.getTableID()).getBanker();
    }

    /**
     * player --- SingelTable ---CircleUnit（0，1，2，3，4）
     * @return SingelTable
     */
    public  SingelTable getSingelTable(){
        for (SingelTable table:tableFastList){
            FastList<SingelTable.CircleUnit> circleUnitFastList=table.getCircleUnitFastList();
            if (circleUnitFastList.get(0).isOccupancy())continue;
            for (SingelTable.CircleUnit circleUnit:circleUnitFastList){
                circleUnit.setOccupancy(true);
            }
            return table;
        }
        return null;
    }
}
